<?php
namespace app\admin\controller;
use app\common\model\SiteConfig;
use utils\Config;
use utils\Result;

class System extends Common
{
    public function index()
    {
        $this->AuthCheck();
        $model = new SiteConfig();

        $list = $model->select();

        if ($this->request->isPost()){

            $param = $this->request->param();

            $where = [];

            foreach ($list as $key => $val){
                foreach ($param as $k => $vo){
                    if ($val['name'] == $k)
                    {
                        $val['value'] = $vo;
                    }
                }
                array_push($where,[
                    'id'    =>  $val['id'],
                    'value' =>  $val['value']
                ]);
            }

            $update = $model->saveAll($where);

            Config::update();

            if ($update) return Result::success('更改成功');

            return Result::error('更改失败');

        }

        $this->assign('config',Config::get());

        return $this->view->fetch();
    }
}